/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MessageIO;

/**
 * A User name class which helps keep track of the usernames and the ip addresses
 * @author VismonteM
 */
public class ChatUsername extends Object
    {
    private String userName;
    private String addy;

    /**
     * Creates a new instance of the ChatUsername with the name and address
     * @param name
     * @param address
     */
    public ChatUsername(String name, String address)
        {
        super();
        if (name == null)
            throw new IllegalArgumentException("Null name inputed");
        if (address == null)
            throw new IllegalArgumentException("IP Address is null");
        userName = name;
        addy = address;
        }

    /**
     * Returns the IP Adrress
     * @return the String representation of the IP address
     */
    public String getAddy()
        {
        String temp = addy.toString();
        return temp.substring(temp.indexOf("/"));
        }

    /**
     * Returns the user name
     * @return returns a String representation of the User Name
     */
    public String getUserName()
        {
        return userName;
        }

    /**
     * Determines if the two objects are equal.  Uses the user name to determine
     * if they are equal
     * @param obj the other object
     * @return true if they are equal. no if they are not equal
     */
    @Override
    public boolean equals(Object obj)
        {
        if (!obj.getClass().equals(this.getClass()))
            return false;
        return ((ChatUsername)(obj)).getUserName().equals(getUserName());
        }

    /**
     * Returns the username and IP Address in a the form of a string
     * @return the username + the IP Address
     */
    @Override
    public String toString()
        {
        return userName + "@" + getAddy();
        }


    
    }
